package com.mars.module.admin.controller;


import java.io.IOException;
import java.util.Arrays;
import java.util.List;

import com.mars.common.enums.BusinessType;
import com.mars.common.result.R;
import com.mars.common.util.ExcelUtils;
import io.swagger.annotations.Api;
import com.mars.framework.annotation.RateLimiter;
import com.mars.module.admin.entity.SysTravelRouteDetails;
import com.mars.framework.annotation.Log;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import com.mars.common.response.PageInfo;
import org.springframework.web.bind.annotation.*;
import lombok.extern.slf4j.Slf4j;
import com.mars.module.admin.service.ISysTravelRouteDetailsService;
import com.mars.module.admin.request.SysTravelRouteDetailsRequest;

import javax.servlet.http.HttpServletResponse;

/**
 * 旅游路线详情控制层
 *
 * @author mars
 * @date 2024-03-26
 */
@Slf4j
@AllArgsConstructor
@RestController
@Api(value = "旅游路线详情接口管理",tags = "8.旅游路线详情接口管理")
@RequestMapping("/admin/sysTravelRouteDetails" )
public class SysTravelRouteDetailsController {

    private final ISysTravelRouteDetailsService iSysTravelRouteDetailsService;

    /**
     * 分页查询旅游路线详情列表
     */
    @ApiOperation(value = "分页查询旅游路线详情列表")
    @PostMapping("/pageList")
    public R<PageInfo<SysTravelRouteDetails>> pageList(@RequestBody SysTravelRouteDetailsRequest sysTravelRouteDetailsRequest) {
        return R.success(iSysTravelRouteDetailsService.pageList(sysTravelRouteDetailsRequest));
    }

    /**
     * 获取旅游路线详情详细信息
     */
    @ApiOperation(value = "获取旅游路线详情详细信息")
    @GetMapping(value = "/query/{id}")
    public R<SysTravelRouteDetails> detail(@PathVariable("id") Long id) {
        return R.success(iSysTravelRouteDetailsService.getById(id));
    }

    /**
     * 新增旅游路线详情
     */
    @Log(title = "新增旅游路线详情", businessType = BusinessType.INSERT)
    @RateLimiter
    @ApiOperation(value = "新增旅游路线详情")
    @PostMapping("/add")
    public R<Void> add(@RequestBody SysTravelRouteDetailsRequest sysTravelRouteDetailsRequest) {
        iSysTravelRouteDetailsService.add(sysTravelRouteDetailsRequest);
        return R.success();
    }

    /**
     * 修改旅游路线详情
     */
    @Log(title = "修改旅游路线详情", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改旅游路线详情")
    @PostMapping("/update")
    public R<Void> edit(@RequestBody SysTravelRouteDetailsRequest sysTravelRouteDetailsRequest) {
        iSysTravelRouteDetailsService.update(sysTravelRouteDetailsRequest);
        return R.success();
    }

    /**
     * 删除旅游路线详情
     */
    @Log(title = "删除旅游路线详情", businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除旅游路线详情")
    @PostMapping("/delete/{ids}")
    public R<Void> remove(@PathVariable Long[] ids) {
        iSysTravelRouteDetailsService.deleteBatch(Arrays.asList(ids));
        return R.success();
    }

    /**
    * 导出旅游路线详情
    *
    * @param response response
    * @throws IOException IOException
    */
    @PostMapping(value = "/export")
    public void exportExcel(HttpServletResponse response,@RequestBody SysTravelRouteDetailsRequest sysTravelRouteDetailsRequest) throws IOException {
        List<SysTravelRouteDetails> list = iSysTravelRouteDetailsService.list(sysTravelRouteDetailsRequest);
        ExcelUtils.exportExcel(list, SysTravelRouteDetails.class, "旅游路线详情信息", response);
    }
}
